﻿$(window).scroll(function() {
    if ($(window).scrollTop() > 200 && $(window).scrollTop() < 500) {
        $(".register-boxy").css("top", -$(window).scrollTop() / 5);

    }
    if ($(window).scrollTop() < 200)
        $(".register-boxy").css("top", 80);
});

$(window).load(function() {

    $(".tb_username").val("tên đăng nhập");
    $(".tb_password").val("mật khẩu");

    $("#watch-expander-head").click(function() {
        $("#submenuprofile").toggleClass("none");
    });

    $("#open-login-form").click(function() {
        alert("??");
    });

    $("#close-notify-msg").click(function() {
        $("#_isp-message_2").hide();
    });

    $("#register_submit_bt").click(function() {
        blockPage();
        $("#register_box_container").load("../Guest/Actions/Register.aspx", function() {

            loadValidator();

            unblockPage();

            $(this).fadeIn("slow");


            $(".register-boxy-close").click(function() {
                $("#register_box_container").fadeOut("slow", function() {
                    $("#register_box_container").html("");
                });

            });


            $(".register-boxy-cancel").click(function() {
                $("#register_box_container").fadeOut("slow", function() {
                    $("#register_box_container").html("");
                });
            });


            $("#refreshverifycode").click(function() {

                $.getJSON("../Guest/Actions/Register.aspx?action=refreshVerificationCode",
                { idcode: $("#securitycode").val() },
                function(result) {
                    $("#securitycode").val(result.Id);
                    $("#refreshverifycodePic").attr("src", result.Hinhanh);
                });
            });


            $(".register-boxy-ok").click(function() {
                var isError = validateForm_subform();
                if (!isError) {
                    blockPage();
                    var acc = { "tenTaiKhoan": $("#username").val(),
                        "matKhau": $("#password").val(),
                        "hoTen": $("#name").val(),
                        "ngaySinh": $("#day").val() + '/' + $("#month").val() + '/' + $("#year").val(),
                        "noiSinh": $("#city").val(),
                        "diaChi": $("#address").val(),
                        "soDienThoai": $("#phone").val(),
                        "maTheTinDung": $("#credit").val(),
                        "gioiTinh": $("#gender").val(),
                        "email": $("#email").val(),
                        "idMaXacNhan": $("#securitycode").val(),
                        "dapAn": $("#security").val()
                    };

                    $.ajax({
                        url: "../Guest/Actions/Register.aspx?action=register",
                        type: "POST",
                        data: acc,
                        error: function(result, status, xhr) {
                            alert(result.responseText);
                            alert("fail");
                        },
                        success: function(result, status, xhr) {
                            unblockPage();
                            if (result.match("success")) {
                                $("#register_box_container").hide();
                                $("#_isp-message_2").show();
                            }
                            else
                                $("#register-error-msg").html(result);
                        }
                    });
                }
            });

        });
    });
});